var tecCardID = GetQueryString("id");
//显示版本号
var version = [];
//显示基本信息
var infomation = [];
for (let i = 0; i < 4; i++) {
    infomation[i] = document.getElementById("infomation" + i).children[0];
}
var sentMessage = {
    "requestType": "initInfoFromTec",
    "tech_id": tecCardID
};
var postData;
$.ajax({
    url: '/task/checkTecCard',
    type: 'post',
    data: sentMessage,
    async: false,
    success: function (data, status) {
        if (status == 'success') {
            postData = data;
        }
    },
    error: function (data, status) {
        if (status == 'error') {
            alert("你的网络有问题！");
        }
    }
});
console.log(postData);
var infomationData = [
    [["项目名称", "产品名称", "部件名称", "焊接方法", "检测时机", "坡口形式", "材质"]],
    [["增感屏", "胶片牌号", "显影时间", "显影温度", "射线源种类", "焦点尺寸", "胶片规格", "像质计型号", "洗片条件", "显影液"]],
    [["工件规格", "焦距", "分段数", "一次透照长度", "检测比例", "像质计灵敏度", "管电压/源活度", "曝光时间", "检测标准", "技术等级", "合格级别", "透照方式"]],
    [["审核员姓名", "编制日期", "审核日期"]]
];
infomationData[0][1] = [
    postData[0].task_pname,
    postData[0].task_product,
    postData[0].wc_pipeName,
    postData[0].wc_weldM,
    postData[0].task_opportunity,
    postData[0].wc_type,
    postData[0].wc_texture
];
infomationData[1][1] = [
    postData[0].tech_screen,
    postData[0].tech_filmBrand,
    postData[0].tech_devTime,
    postData[0].tech_devT,
    postData[0].tech_ray,
    postData[0].tech_focus,
    postData[0].tech_filmV,
    postData[0].tech_IQIV,
    postData[0].tech_devCondition,
    postData[0].tech_liquor
];
infomationData[2][1] = [
    postData[0].wc_spec,
    postData[0].tech_focalDis,
    postData[0].tech_seg,
    postData[0].tech_tranLen,
    postData[0].wc_scale,
    postData[0].tech_IQISen,
    postData[0].tech_V,
    postData[0].tech_time,
    postData[0].task_standard,
    postData[0].task_level,
    postData[0].wc_qua,
    postData[0].tech_tranType
];
version = [postData[0].tech_id, postData[0].tech_version];
document.getElementById("version0").innerHTML = "工艺卡号/版本号: " + version[0];
document.getElementById("version1").innerHTML = "工艺规程号/版本: " + version[1];
var name;
$.ajax({
    url: '/user/username',
    type: 'post',
    data: { "user_id": postData[0].tech_verify },
    async: false,
    success: function (data, status) {
        if (status == 'success') {
            name = data[0] == undefined ? "" : data[0].user_name;
        }
    },
    error: function (data, status) {
        if (status == 'error') {
            alert("你的网络有问题！");
        }
    }
});
infomationData[3][1] = [
    name,
    postData[0].tech_date == undefined ? "" : postData[0].tech_date.substring(0, 10),
    postData[0].tech_verify_date
];
for (let j = 0; j < 4; j++) {
    for (let i = 0; i < infomationData[j][0].length; i++) {
        let tr = document.createElement("tr");
        if (i % 3 === 0) {
            infomation[j].appendChild(tr);
        }
        let td = document.createElement("td");
        td.setAttribute("class", "td-shadows");
        td.setAttribute("align", "center");
        td.innerHTML = infomationData[j][0][i];
        infomation[j].children[infomation[j].childElementCount - 1].appendChild(td);
        td = document.createElement("td");
        td.setAttribute("align", "center");
        td.innerHTML = infomationData[j][1][i];
        infomation[j].children[infomation[j].childElementCount - 1].appendChild(td);
    }
}
function OnPass() {
    var date = new Date();
    $.ajax({
        url: '/task/checkTecCard',
        type: 'post',
        data: {
            "tech_state": 1,
            "tech_reason": "",
            "tech_id": tecCardID,
            "task_id": postData[0].tech_tid,
            "tech_verify":user.user_id,
            "tech_verify_date":date.getFullYear() + "-" + (date.getMonth() + 1) + "-" + date.getDate(),
            "requestType": "updateInfoFromTec"
        },
        async: false,
        success: function (data, status) {
            if (status == 'success') {
                alert("提交成功");
                history.back();
            }
        },
        error: function (data, status) {
            if (status == 'error') {
                alert("你的网络有问题！");
            }
        }
    });
}

function OnNoPass() {
    document.getElementById("noPass").setAttribute("onclick", "OnCommitNoPass();");
    document.getElementById("checkDescribe").setAttribute("class", "col-md-12");
    document.getElementById("noPass").innerHTML = "<i class=\"ace-icon fa fa-close bigger-120\"></i>提交";
    document.getElementById('pass').style.display = 'none'
}

function OnCommitNoPass() {
    console.log(document.getElementById("reason").value)
    $.ajax({
        url: '/task/checkTecCard',
        type: 'post',
        data: {
            "tech_state": 2,
            "tech_reason": document.getElementById("reason").value,
            "tech_id": tecCardID,
            "task_id": postData[0].tech_tid,
            "requestType": "updateInfoFromTec"
        },
        async: false,
        success: function (data, status) {
            if (status == 'success') {
                alert("提交成功");
                history.back();
            }
        },
        error: function (data, status) {
            if (status == 'error') {
                alert("你的网络有问题！");
            }
        }
    });
}